<template>
  <el-card style="margin: 50px">
    <el-form ref="userRef" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="公司邮箱" prop="email">
        <el-input v-model="form.email" maxlength="30" />
      </el-form-item>
      <el-form-item label="公司简介" prop="detail">
        <el-input v-model="form.detail" maxlength="11" />
      </el-form-item>
      <el-form-item label="公司地址" prop="website">
        <el-input v-model="form.website" maxlength="50" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submit">保存</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup>
import { updateUserProfile } from "@/api/system/user";
import { getCompany, editCompany } from "@/api/personality/eva";

const props = defineProps({
  user: {
    type: Object,
  },
});

const { proxy } = getCurrentInstance();

const form = ref({});
const rules = ref({
  website: [{ required: true, message: "公司地址不能为空", trigger: "blur" }],
  email: [
    { required: true, message: "邮箱地址不能为空", trigger: "blur" },
    {
      type: "email",
      message: "请输入正确的邮箱地址",
      trigger: ["blur", "change"],
    },
  ],
  detail: [{ required: true, message: "公司简介不能为空", trigger: "blur" }],
});

/** 提交按钮 */
function submit() {
  proxy.$refs.userRef.validate((valid) => {
    if (valid) {
      editCompany(form.value).then((response) => {
        proxy.$modal.msgSuccess("修改成功");
      });
    }
  });
}

onMounted(() => {
  getCompany().then((response) => {
    form.value = response.data;
  });
});
</script>
